/*
 * 文件名：RoleInfoTransactionImp.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：ozm
 * 修改时间：2013-1-30
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.facility.device.transaction.imp;

import com.wootide.cms.common.CMSRuntimeException;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.dao.CommonDao;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.facility.device.dao.DeviceInfoDao;
import com.wootide.cms.service.facility.device.pojo.DeviceInfo;
import com.wootide.cms.service.facility.device.transaction.DeviceInfoTransaction;

/**
 * 用户事物层实现层
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 * @author ozm
 * @version 2013-1-30
 * @see DeviceInfoTransactionImp
 * @since 2013-1-30上午9:44:19
 */
public class DeviceInfoTransactionImp implements DeviceInfoTransaction
{
    // 注入运行日志
    private RunLog runLog;
    
    //公共数据访问层实例
    private CommonDao commonDao;
    
    //角色数据访问层实例
    private DeviceInfoDao deviceInfoDao;
    
    /**
     * 
     * Description: 分页查询
     * Implement: <br>
     * @param page 分页参数
     * @param queryConditon 查询条件
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:23:32
     */
    public QueryResults queryForPages(Page page, QueryCondition queryConditon)
    {
        
        // 打印方法入口参数
        runLog.debug("page=" + page);
        runLog.debug("queryConditon=" + queryConditon);
        QueryResults queryResults = commonDao.queryForPages(page, queryConditon);
        return queryResults;
    }
    
    @Override
    public DeviceInfo delDeviceInfo(Integer innerIndex)
    {
        DeviceInfo oldDeviceInfo = deviceInfoDao.findDeviceInfoById(innerIndex);
        //判断要删除的记录是否存在
        if (null == oldDeviceInfo)
        {
            throw new CMSRuntimeException(
                    "oldDeviceInfo not Exist!",
                    ErrorCodes.Consumables.ConsumablesInfo.COMSUMABLESINFO_EXIST);
        }
        
        commonDao.delOneObject(oldDeviceInfo);
        
        return oldDeviceInfo;
    }
    
    
    @Override
    public void addDeviceInfo(DeviceInfo deviceInfo)
    {

        // 打印方法入口参数
        runLog.debug("deviceInfo=" + deviceInfo);
        // 根据易耗品名检查唯一性
        Integer num = deviceInfoDao.findNumByDeviceInfoNum(deviceInfo.getDeviceNum());
        //易耗品记录已经存在
        if (num > 0)
        {
            throw new CMSRuntimeException("deviceInfo Existed!",
                    ErrorCodes.Consumables.ConsumablesInfo.COMSUMABLESINFO_EXIST);
        }
        commonDao.addOneObject(deviceInfo);
    
        
    }
    
    @Override
    public DeviceInfo viewDeviceInfo(Integer innerIndex)
    {
        // 打印方法入口参数
        runLog.debug("innerIndex=" + innerIndex);
        DeviceInfo deviceInfo = deviceInfoDao.findDeviceInfoById(innerIndex);
        return deviceInfo;
    }
    
    public RunLog getRunLog()
    {
        return runLog;
    }
    
    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }
    
    public CommonDao getCommonDao()
    {
        return commonDao;
    }
    
    public void setCommonDao(CommonDao commonDao)
    {
        this.commonDao = commonDao;
    }
    
    public DeviceInfoDao getDeviceInfoDao()
    {
        return deviceInfoDao;
    }
    
    public void setDeviceInfoDao(DeviceInfoDao deviceInfoDao)
    {
        this.deviceInfoDao = deviceInfoDao;
    }
    
}
